<?php

// 告诉浏览器这个文件的类型
header('Content-Type: application/rss+xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

require_once '../inc/functions.inc.php';
require_once '../inc/db.inc.php';

try {
	$link = new PDO(DB_INFO, DB_USERNAME, DB_PASSWORD);
} catch (PDOException $e) {
	die("connection failed: ".$e->getMessage());
}

$content = retrieve_entries($link, 'blog');
array_pop($content);
$content = santinize_data($content);
// $date = date(DATE_RSS, strtotime($content['created']));

?>
<rss version="2.0">
	<channel>
	<title>小博客</title>
	<link>http://<?php echo $_SERVER["HTTP_HOST"]?>/SimpleBlog/</link>
	<description>小博客应用。</description>
	<language>zh</language>

	<?php foreach ($content[0] as $val):
		$title = $val["title"];
		$url = "http://".$_SERVER["HTTP_HOST"]."/SimpleBlog/blog/".
			urlencode(urldecode($val["url"]));
		$entry = htmlentities($val["entry"]); ?>
		<item>
			<title><?php echo $title?></title>
			<description><?php echo $entry?></description>
			<link><?php echo $url?></link>
			<guid><?php echo $url?></guid>
			<pubDate><?php echo date(DATE_RSS, strtotime($val['created']));?></pubDate>
		</item>
	<?php endforeach;?>

	</channel>
</rss>
